var ScenePointLibrary = function(options) {
	this.ctx = options.ctx;
	this.editor = options.editor;
	this.globe = options.editor.globe;
	this.sceneId = options.sceneId;
	this.isOpen = false;
}

ScenePointLibrary.prototype.open = function() {
	var _this = this;
	if (_this.isOpen) {
		return;
	}
	layer.load(2);
	var res = common_ajax.ajaxFunc('get', _this.ctx + "/scene/point/library", {}, "html", null);
	layer.closeAll('loading');
	if (!res) {
		layer.alert('系统异常！');
		return;
	}
	
	layer.closeAll();
	layer.open({
		id: 'scenePointLibrary',
		title: '图标库',
		type: 1,
		area: '220px',
		content: res,
		shade: 0,
		offset: 'l',
		skin: 'layui-layer layui-layer-adminRight layui-layer-city',
		success: function(layero, dIndex) {
			_this.isOpen = true;
			_this.dIndex = dIndex;
			$(layero).children('.layui-layer-content').css('overflow', 'hidden');
			$(layero).children('.layui-layer-content').css('height', 'calc(100% - 30px)');
			form.render();
			_this.loadList();
		},
		end: function() {
			_this.isOpen = false;
			_this.dIndex = null;
			if(_this.drawPPoint){
				_this.drawPPoint.destroy();
				_this.drawPPoint=null;
			}
		}
	});
}

ScenePointLibrary.prototype.loadList = function(classifyId) {
	var _this = this;
	var res = common_ajax.ajaxFunc('get', _this.ctx + "/scene/point/listDataForIcon", { classifyId: classifyId || $("#point-icon-classify-select").val() }, "json", null);
	if (0 == res.code) {
		res.ctx = _this.ctx;
		laytpl(selectModelsScript.innerHTML).render(res, function(html) {
			$('#select-point-icon-list').html(html);
			$(".IconImageList>.content>.item>.icon").on('click', function() {
				_this.add($(this).attr('id'));
			})
		});
	}
}

ScenePointLibrary.prototype.add=function(id){
	let _this=this;
	if(_this.drawPPoint){
		_this.drawPPoint.destroy();
		_this.drawPPoint=null;
	}
	layer.load(2);
	var res = common_ajax.ajaxFunc('get', _this.ctx + "/resources/icon/getById", {
		id:id,
	}, "json", null);
	layer.closeAll('loading');
    if (200==res.code) {
    	let billboard=res.data;
    	let options={
    		id:	_this.globe.getUuid(),
    		name:billboard.name||'',
    		code:billboard.code||"",
    		type:'Point',
    		thing:{
				image:this.ctx+billboard.url,
				width:billboard.width*1,
				height:billboard.height*1,
				bShow:'1',
			}
    	}
    	_this.drawPPoint=_this.globe.drawPPoint(options);
    	_this.drawPPoint.on('success',function(obj){
    		if(obj){
    			_this.globe.addPointToLayer(obj);
	            var formData={}; 
                formData['scenePoint.id']=obj.id;
                formData['scenePoint.name']=obj.name;
                formData['scenePoint.code']=obj.code;
                formData['scenePoint.type']=obj.type;
                formData['scenePoint.x']=obj.position.x;
                formData['scenePoint.y']=obj.position.y;
                formData['scenePoint.z']=obj.position.z;
				formData['scenePoint.scale']=obj.thing.scale;
				formData['scenePoint.image']=_this.getImage(obj);
				formData['scenePoint.height']=obj.thing.height;
				formData['scenePoint.width']=obj.thing.width;
				formData['scenePoint.bShow']=obj.thing.bShow;
                formData['scenePoint.sceneId']=_this.sceneId;
                layer.load(2);
    			var res = common_ajax.ajaxFunc('get', _this.ctx + "/scene/point/save",formData, "json", null);
    			layer.closeAll('loading');
    			if(200==res.code){
    				layer.msg(res?res.message:'系统异常!', {icon: 1});
    			}else{
    				 layer.msg(res?res.message:'系统异常!', {icon: 2});
    			}
    		}
    	});
    	_this.drawPPoint.on('error',function(e){
    	});
    	_this.drawPPoint.on('complete',function(e){
    	});
    } else {
        layer.msg(res?res.message:'系统异常!', {icon: 2});
    }
}

ScenePointLibrary.prototype.editPPoint=function(obj){
	var _this = this;
	_this.model=obj;
	if (_this.isOpenEditPPoint) {
		_this.closeEditTool();
		_this.loadFormData();
		_this.insTb.reload();
		return;
	}
	layer.load(2);
	var res = common_ajax.ajaxFunc('get', _this.ctx + "/scene/point/edit", {}, "html", null);
	layer.closeAll('loading');
	if (!res) {
		layer.alert('系统异常！');
		return;
	}
	layer.open({
		id: 'editPPoint',
		title: '属性编辑',
		type: 1,
		offset: '40px',
		area: '390px',
		content: res,
		shade: 0,
		offset: 'l',
		skin: 'layui-layer layui-layer-adminRight layui-layer-city',
		success: function(layero, dIndex) {
			_this.isOpenEditPPoint = true;
			_this.editPPointIndex = dIndex;
			$(layero).children('.layui-layer-content').css('overflow', 'hidden');
			$(layero).children('.layui-layer-content').css('height', 'calc(100% - 30px)');
			_this.loadFormData();
			_this.renderForm();
			_this.renderProperty();
			$("#pmodelTranslationBtn").on('click', function() {
				if(!$(this).hasClass("scene-btn-disabled")){
					$(this).addClass("scene-btn-disabled");
					_this.closeEditTool();
				}else{
					$(this).removeClass("scene-btn-disabled");
					_this.createEditTool(_this.model);
				}
			});
			form.render();
		},
		end: function() {
			_this.isOpenEditPPoint = false;
			_this.editPPointIndex = null;
			_this.closeEditTool();
		}
	});
}

ScenePointLibrary.prototype.renderForm = function(){
	var _this = this;
	
	$('#pointZ').on('input', function() {
		 if(_this.model){
			 _this.model.updatePosition({
				 x:$("#pointX").val(),
				 y:$("#pointY").val(),
				 z:$("#pointZ").val(),
			 });
			 if(_this.EditPPointTool){
				 _this.EditPPointTool.update(_this.model);
			 }
		 }
	 });
	
	$('#scenePointPositionBtn').click(function() {
		_this.globe.flyToPoisition(_this.model);
	});
	
	////图标
	
	form.on('select(bShow)', function(data){
		 if(_this.model){
			 _this.model.updateBShow(data.value);
		 }
 	});
	
	
	$('#scenePointScale').on('input', function() {
		 if(_this.model){
			 _this.model.updateBScale($('#scenePointScale').val()*1);
		 }
	});
	
	$('#scene-point-image-btn').click(function() {
		_this.updateImage();
	});
	
	////////////////////////////////标签
	form.on('select(lShow)', function(data){
		 if(_this.model){
			 _this.model.updateLShow(data.value);
		 }
  	});
	
	$('#lFontSize').on('input', function() {
		 if(_this.model){
			 _this.model.updateLFontSize($('#lFontSize').val());
		 }
	});
	
	$('#lScale').on('input', function() {
		 if(_this.model){
			 _this.model.updateLScale($('#lScale').val());
		 }
	});
	
	
	
	
	$('#lFontFamily').on('input', function() {
		 if(_this.model){
			 _this.model.updateLFontFamily($('#lFontFamily').val());
		 }
	});
	
	$('#lPOffsetX').on('input', function() {
		 if(_this.model){
			 _this.model.updateLPOffset($('#lPOffsetX').val(),$('#lPOffsetY').val());
		 }
	});
	
	$('#lPOffsetY').on('input', function() {
		 if(_this.model){
			 _this.model.updateLPOffset($('#lPOffsetX').val(),$('#lPOffsetY').val());
		 }
	});
	
	form.on('select(lShowBackground)', function(data){
		 if(_this.model){
			 _this.model.updateLShowBackground(data.value);
		 }
 	});
	
	//背景色
	colorpicker.render({
		elem: '#lBackgroundColor',
		color: (_this.model.thing&&_this.model.thing.lBackgroundColor)?_this.model.thing.lBackgroundColor:null,
		format: 'rgb',
		predefine: true,
		alpha: true,
		done: function(color) {
			$('#lBackgroundColor-input').val(color); //向隐藏域赋值
			color || this.change(color); //清空时执行 change
		},
		change: function(color) {
			 if(_this.model){
				 _this.model.updateLBackgroundColor(color);
			 }
		}
	}); 
	
	form.on('select(lStyle)', function(data){
		 if(_this.model){
			 _this.model.updateLStyle(data.value);
		 }
	});
	
	
	$('#lOutlineWidth').on('input', function() {
		 if(_this.model){
			 _this.model.updateLOutlineWidth($('#lOutlineWidth').val());
		 }
	});
	

	//边框色
	colorpicker.render({
		elem: '#lOutlineColor',
		color: (_this.model.thing&&_this.model.thing.lOutlineColor)?_this.model.thing.lOutlineColor:null,
		format: 'rgb',
		predefine: true,
		alpha: true,
		done: function(color) {
			$('#lOutlineColor-input').val(color); //向隐藏域赋值
			color || this.change(color); //清空时执行 change
		},
		change: function(color) {
			 if(_this.model){
				 _this.model.updateLOutlineColor(color);
			 }
		}
	});
	
	form.on('select(lVerticalOrigin)', function(data){
		 if(_this.model){
			 _this.model.updateLVerticalOrigin(data.value);
		 }
	});
	
	form.on('select(lHorizontalOrigin)', function(data){
		 if(_this.model){
			 _this.model.updateLHorizontalOrigin(data.value);
		 }
	});
	
	///////////////////////////////点
	form.on('select(pShow)', function(data){
		 if(_this.model){
			 _this.model.updatePShow(data.value);
		 }
	});
	
	$('#pSize').on('input', function() {
		 if(_this.model){
			 _this.model.updatePSize($('#pSize').val());
		 }
	});
	
	colorpicker.render({
		elem: '#pColor',
		color: (_this.model.thing&&_this.model.thing.pColor)?_this.model.thing.pColor:null,
		format: 'rgb',
		predefine: true,
		alpha: true,
		done: function(color) {
			$('#pColor-input').val(color); //向隐藏域赋值
			color || this.change(color); //清空时执行 change
		},
		change: function(color) {
			 if(_this.model){
				 _this.model.updatePColor(color);
			 }
		}
	});
	
	$('#pOutlineWidth').on('input', function() {
		 if(_this.model){
			 _this.model.updatePOutlineWidth($('#pOutlineWidth').val());
		 }
	});

	colorpicker.render({
		elem: '#pOutlineColor',
		color: (_this.model.thing&&_this.model.thing.pOutlineColor)?_this.model.thing.pOutlineColor:null,
		format: 'rgb',
		predefine: true,
		alpha: true,
		done: function(color) {
			$('#pOutlineColor-input').val(color); //向隐藏域赋值
			color || this.change(color); //清空时执行 change
		},
		change: function(color) {
			 if(_this.model){
				 _this.model.updatePOutlineColor(color);
			 }
		}
	});
	
	$('#scenePointDeleteBtn').click(function() {
		layer.confirm('确定要删除模型吗？', {
			shade: .1
		}, function(index) {
			if(_this.model){
				_this.delete(_this.model);
			}
		}, function(index) {
			layer.close(index);
			return false;
		});
	});
	
	//图标缩放
	form.on('select(isBScaleByDistance)', function(data){
		 if(_this.model){
			 _this.model.updateBScaleByDistance({
				 isScaleByDistance: data.value
			 });
		 }
	});
	
	$('#bScaleByDistanceNear').on('input', function() {
		 if(_this.model){
			 _this.model.updateBScaleByDistance({
				 near: $('#bScaleByDistanceNear').val()
			 });
		 }
	});
	$('#bScaleByDistanceNearValue').on('input', function() {
		 if(_this.model){
			 _this.model.updateBScaleByDistance({
				 nearValue: $('#bScaleByDistanceNearValue').val()
			 });
		 }
	});	
	
	$('#bScaleByDistanceFar').on('input', function() {
		 if(_this.model){
			 _this.model.updateBScaleByDistance({
				 far: $('#bScaleByDistanceFar').val()
			 });
		 }
	});
	$('#bScaleByDistanceFarValue').on('input', function() {
		 if(_this.model){
			 _this.model.updateBScaleByDistance({
				 farValue: $('#bScaleByDistanceFarValue').val()
			 });
		 }
	});	
	
	
	form.on('select(isBTranslucencyByDistance)', function(data){
		 if(_this.model){
			 _this.model.updateBTranslucencyByDistance({
				 isTranslucencyByDistance: data.value
			 });
		 }
	});
	
	$('#bTranslucencyByDistanceNear').on('input', function() {
		 if(_this.model){
			 _this.model.updateBTranslucencyByDistance({
				 near: $('#bTranslucencyByDistanceNear').val()
			 });
		 }
	});
	$('#bTranslucencyByDistanceNearValue').on('input', function() {
		 if(_this.model){
			 _this.model.updateBTranslucencyByDistance({
				 nearValue: $('#bTranslucencyByDistanceNearValue').val()
			 });
		 }
	});	
	
	$('#bTranslucencyByDistanceFar').on('input', function() {
		 if(_this.model){
			 _this.model.updateBTranslucencyByDistance({
				 far: $('#bTranslucencyByDistanceFar').val()
			 });
		 }
	});
	$('#bTranslucencyByDistanceFarValue').on('input', function() {
		 if(_this.model){
			 _this.model.updateBTranslucencyByDistance({
				 farValue: $('#bTranslucencyByDistanceFarValue').val()
			 });
		 }
	});		
	
	//标签
	form.on('select(isLScaleByDistance)', function(data){
		 if(_this.model){
			 _this.model.updateLScaleByDistance({
				 isScaleByDistance: data.value
			 });
		 }
	});
	
	$('#lScaleByDistanceNear').on('input', function() {
		 if(_this.model){
			 _this.model.updateLScaleByDistance({
				 near: $('#lScaleByDistanceNear').val()
			 });
		 }
	});
	$('#lScaleByDistanceNearValue').on('input', function() {
		 if(_this.model){
			 _this.model.updateLScaleByDistance({
				 nearValue: $('#lScaleByDistanceNearValue').val()
			 });
		 }
	});	
	
	$('#lScaleByDistanceFar').on('input', function() {
		 if(_this.model){
			 _this.model.updateLScaleByDistance({
				 far: $('#lScaleByDistanceFar').val()
			 });
		 }
	});
	$('#lScaleByDistanceFarValue').on('input', function() {
		 if(_this.model){
			 _this.model.updateLScaleByDistance({
				 farValue: $('#lScaleByDistanceFarValue').val()
			 });
		 }
	});	
	
	
	form.on('select(isLTranslucencyByDistance)', function(data){
		 if(_this.model){
			 _this.model.updateLTranslucencyByDistance({
				 isTranslucencyByDistance: data.value
			 });
		 }
	});
	
	$('#lTranslucencyByDistanceNear').on('input', function() {
		 if(_this.model){
			 _this.model.updateLTranslucencyByDistance({
				 near: $('#lTranslucencyByDistanceNear').val()
			 });
		 }
	});
	$('#lTranslucencyByDistanceNearValue').on('input', function() {
		 if(_this.model){
			 _this.model.updateLTranslucencyByDistance({
				 nearValue: $('#lTranslucencyByDistanceNearValue').val()
			 });
		 }
	});	
	
	$('#lTranslucencyByDistanceFar').on('input', function() {
		 if(_this.model){
			 _this.model.updateLTranslucencyByDistance({
				 far: $('#lTranslucencyByDistanceFar').val()
			 });
		 }
	});
	$('#lTranslucencyByDistanceFarValue').on('input', function() {
		 if(_this.model){
			 _this.model.updateLTranslucencyByDistance({
				 farValue: $('#lTranslucencyByDistanceFarValue').val()
			 });
		 }
	});		
	
	form.on('select(isLPixelOffsetScaleByDistance)', function(data){
		 if(_this.model){
			 _this.model.updateLPixelOffsetScaleByDistance({
				 isPixelOffsetScaleByDistance: data.value
			 });
		 }
	});
	
	$('#lPixelOffsetScaleByDistanceNear').on('input', function() {
		 if(_this.model){
			 _this.model.updateLPixelOffsetScaleByDistance({
				 near: $('#lPixelOffsetScaleByDistanceNear').val()
			 });
		 }
	});
	$('#lPixelOffsetScaleByDistanceNearValue').on('input', function() {
		 if(_this.model){
			 _this.model.updateLPixelOffsetScaleByDistance({
				 nearValue: $('#lPixelOffsetScaleByDistanceNearValue').val()
			 });
		 }
	});	
	
	$('#lPixelOffsetScaleByDistanceFar').on('input', function() {
		 if(_this.model){
			 _this.model.updateLPixelOffsetScaleByDistance({
				 far: $('#lPixelOffsetScaleByDistanceFar').val()
			 });
		 }
	});
	$('#lPixelOffsetScaleByDistanceFarValue').on('input', function() {
		 if(_this.model){
			 _this.model.updateLPixelOffsetScaleByDistance({
				 farValue: $('#lPixelOffsetScaleByDistanceFarValue').val()
			 });
		 }
	});		
	
	//点
	form.on('select(isPScaleByDistance)', function(data){
		 if(_this.model){
			 _this.model.updatePScaleByDistance({
				 isScaleByDistance: data.value
			 });
		 }
	});
	
	$('#pScaleByDistanceNear').on('input', function() {
		 if(_this.model){
			 _this.model.updatePScaleByDistance({
				 near: $('#pScaleByDistanceNear').val()
			 });
		 }
	});
	$('#pScaleByDistanceNearValue').on('input', function() {
		 if(_this.model){
			 _this.model.updatePScaleByDistance({
				 nearValue: $('#pScaleByDistanceNearValue').val()
			 });
		 }
	});	
	
	$('#pScaleByDistanceFar').on('input', function() {
		 if(_this.model){
			 _this.model.updatePScaleByDistance({
				 far: $('#pScaleByDistanceFar').val()
			 });
		 }
	});
	$('#pScaleByDistanceFarValue').on('input', function() {
		 if(_this.model){
			 _this.model.updatePScaleByDistance({
				 farValue: $('#pScaleByDistanceFarValue').val()
			 });
		 }
	});	
	
	form.on('select(isPTranslucencyByDistance)', function(data){
		 if(_this.model){
			 _this.model.updatePTranslucencyByDistance({
				 isTranslucencyByDistance: data.value
			 });
		 }
	});
	
	$('#pTranslucencyByDistanceNear').on('input', function() {
		 if(_this.model){
			 _this.model.updatePTranslucencyByDistance({
				 near: $('#pTranslucencyByDistanceNear').val()
			 });
		 }
	});
	$('#pTranslucencyByDistanceNearValue').on('input', function() {
		 if(_this.model){
			 _this.model.updatePTranslucencyByDistance({
				 nearValue: $('#pTranslucencyByDistanceNearValue').val()
			 });
		 }
	});	
	
	$('#pTranslucencyByDistanceFar').on('input', function() {
		 if(_this.model){
			 _this.model.updatePTranslucencyByDistance({
				 far: $('#pTranslucencyByDistanceFar').val()
			 });
		 }
	});
	$('#pTranslucencyByDistanceFarValue').on('input', function() {
		 if(_this.model){
			 _this.model.updatePTranslucencyByDistance({
				 farValue: $('#pTranslucencyByDistanceFarValue').val()
			 });
		 }
	});	
	
	
	form.on('submit(submitPointEditForm)', function(data) {
		layer.load(2);
		var formData = {};
		for (var key in data.field) {
			formData['scenePoint.' + key] = data.field[key];
		}
		var res = common_ajax.ajaxFunc('post', _this.ctx + "/scene/point/save", formData, "json", null);
		layer.closeAll('loading');
		if (res && 200 == res.code) {
			layer.msg(res.message, {icon: 1});
			if(_this.model){
				_this.model.updateName(res.data);
		 	}
			if(_this.icondIndex){
				layer.close(_this.icondIndex);
			}
		} else {
			layer.msg(res.message, {icon: 2});
		}
		return false;
	});
}

ScenePointLibrary.prototype.loadFormData=function(){
	let _this=this;
	let data={};
	if(_this.model){
		data={
			id:_this.model.id,
			name:_this.model.name||'',
			code:_this.model.code||'',
			
			x:_this.model.position.x||'',
			y:_this.model.position.y||'',
			z:_this.model.position.z||0,
			
			image:this.getImage(_this.model),
			scale:_this.model.thing.scale||1,
			width:_this.model.thing.width,
			height:_this.model.thing.height,
			bShow:_this.model.thing.bShow,
			
			pShow:_this.model.thing.pShow,
			pSize:_this.model.thing.pSize,
			pOutlineColor:_this.model.thing.pOutlineColor,
			pOutlineWidth:_this.model.thing.pOutlineWidth,
			pColor:_this.model.thing.pColor,
			
			lShow:_this.model.thing.lShow,
			lBackgroundColor:_this.model.thing.lBackgroundColor,
			lShowBackground:_this.model.thing.lShowBackground,
			lStyle:_this.model.thing.lStyle,
			lOutlineWidth:_this.model.thing.lOutlineWidth,
			lOutlineColor:_this.model.thing.lOutlineColor,
			lVerticalOrigin:_this.model.thing.lVerticalOrigin,
			lHorizontalOrigin:_this.model.thing.lHorizontalOrigin,
			lPOffsetX:_this.model.thing.lPOffsetX,
			lPOffsetY:_this.model.thing.lPOffsetY,
			lFontSize:_this.model.thing.lFontSize,
			lFontFamily:_this.model.thing.lFontFamily,
			lScale:_this.model.thing.lScale,
			
			isBTranslucencyByDistance:_this.model.thing.isBTranslucencyByDistance,
			bTranslucencyByDistanceFar:_this.model.thing.bTranslucencyByDistanceFar,
			pScaleByDistanceNearValue:_this.model.thing.pScaleByDistanceNearValue,
			pTranslucencyByDistanceNearValue:_this.model.thing.pTranslucencyByDistanceNearValue,
			lPixelOffsetScaleByDistanceNear:_this.model.thing.lPixelOffsetScaleByDistanceNear,
			isBScaleByDistance:_this.model.thing.isBScaleByDistance,
			isLScaleByDistance:_this.model.thing.isLScaleByDistance,
			bScaleByDistanceNearValue:_this.model.thing.bScaleByDistanceNearValue,
			isLTranslucencyByDistance:_this.model.thing.isLTranslucencyByDistance,
			lTranslucencyByDistanceFarValue:_this.model.thing.lTranslucencyByDistanceFarValue,
			bTranslucencyByDistanceNear:_this.model.thing.bTranslucencyByDistanceNear,
			bTranslucencyByDistanceNearValue:_this.model.thing.bTranslucencyByDistanceNearValue,
			pTranslucencyByDistanceNear:_this.model.thing.pTranslucencyByDistanceNear,
			pScaleByDistanceFar:_this.model.thing.pScaleByDistanceFar,
			isLPixelOffsetScaleByDistance:_this.model.thing.isLPixelOffsetScaleByDistance,
			isPTranslucencyByDistance:_this.model.thing.isPTranslucencyByDistance,
			pTranslucencyByDistanceFar:_this.model.thing.pTranslucencyByDistanceFar,
			lScaleByDistanceNearValue:_this.model.thing.lScaleByDistanceNearValue,
			pTranslucencyByDistanceFarValue:_this.model.thing.pTranslucencyByDistanceFarValue,
			lScaleByDistanceFar:_this.model.thing.lScaleByDistanceFar,
			lPixelOffsetScaleByDistanceFarValue:_this.model.thing.lPixelOffsetScaleByDistanceFarValue,
			bScaleByDistanceNear:_this.model.thing.bScaleByDistanceNear,
			lScaleByDistanceFarValue:_this.model.thing.lScaleByDistanceFarValue,
			pScaleByDistanceFarValue:_this.model.thing.pScaleByDistanceFarValue,
			lPixelOffsetScaleByDistanceFar:_this.model.thing.lPixelOffsetScaleByDistanceFar,
			bScaleByDistanceNear:_this.model.thing.bScaleByDistanceNear,
			lScaleByDistanceFarValue:_this.model.thing.lScaleByDistanceFarValue,
			pScaleByDistanceFarValue:_this.model.thing.pScaleByDistanceFarValue,
			lPixelOffsetScaleByDistanceFar:_this.model.thing.lPixelOffsetScaleByDistanceFar,
			
			lTranslucencyByDistanceNear:_this.model.thing.lTranslucencyByDistanceNear,
			lTranslucencyByDistanceFar:_this.model.thing.lTranslucencyByDistanceFar,
			isPScaleByDistance:_this.model.thing.isPScaleByDistance,
			pScaleByDistanceNear:_this.model.thing.pScaleByDistanceNear,
			lPixelOffsetScaleByDistanceNearValue:_this.model.thing.lPixelOffsetScaleByDistanceNearValue,
			bScaleByDistanceFar:_this.model.thing.bScaleByDistanceFar,
			lScaleByDistanceNear:_this.model.thing.lScaleByDistanceNear,
			lTranslucencyByDistanceNearValue:_this.model.thing.lTranslucencyByDistanceNearValue,
			bScaleByDistanceFarValue:_this.model.thing.bScaleByDistanceFarValue,
			bTranslucencyByDistanceFarValue:_this.model.thing.bTranslucencyByDistanceFarValue,
		}	
	}
	form.val('pointEditForm', data);
	$("#scene-point-image").attr('src',_this.ctx+data.image);
	_this.createEditTool(_this.model);
	return data;
}

ScenePointLibrary.prototype.getImage = function(obj) {
	if(obj.thing && obj.thing.image && obj.thing.image.indexOf(this.ctx) != -1){
		return obj.thing.image.substring(this.ctx.length,obj.thing.image.length)
	}
	return obj.thing.image;
}

ScenePointLibrary.prototype.renderProperty = function(){
	var _this = this;
	_this.insTb=table.render({
	    elem: '#tablePointProperty',
	    url: _this.ctx +'/scene/property/listData',
	    page: false,
	    where:{
	    	thingId:_this.model.id
	    },
	    cols: [[
	        {field: 'label', sort: false, title: '标签', edit: 'text'},
	        {field: 'value', sort: false, title: '值', edit: 'text'},
	        {align: 'center', toolbar: '#tablePointPropertyScript', title: '操作',width:120}
	    ]]
	});
	
    // 添加
    $('#addPointPropertyBtn').click(function () {
        showEditModel();
    });

    // 工具条点击事件
    table.on('tool(tablePointProperty)', function (obj) {
        var data = obj.data;
        var layEvent = obj.event;
        if (layEvent === 'edit') { // 修改
            showEditModel(data);
        } else if (layEvent === 'del') { // 删除
            doDel(obj);
        }
        
    });

    // 删除
    function doDel(obj) {
        layer.confirm('确定要删除“' + obj.data.label + '”吗？', {
            skin: 'layui-layer-admin',
            shade: .1
        }, function (i) {
            layer.close(i);
            layer.load(2);
    		var res = common_ajax.ajaxFunc('post', _this.ctx + "/scene/property/delete", {id:obj.data.id}, "json", null);
            layer.closeAll('loading');
            if (res.code == 200) {
                layer.msg(res.message, {icon: 1});
				_this.insTb.reload();
            } else {
                layer.msg(res.message, {icon: 2});
            }
        });
    }

    // 显示编辑弹窗
    function showEditModel(nData) {
        layer.open({
            type: 1,
            title: (nData ? '修改' : '添加'),
            content: $('#pointPointPropertyScript').html(),
            success: function (layero, dIndex) {
				$(layero).children('.layui-layer-content').css('overflow', 'hidden');
                form.val('pointPropertyForm', nData);  // 回显数据
                form.on('submit(modelSubmitPointPropertyForm)', function (data) {
                    layer.load(2);
                    var formData={}; 
                    for(var key in data.field){
                    	formData['sceneProperty.'+key]=data.field[key];
                    }
                    formData['sceneProperty.thingId']=_this.model.id; 
                    formData['sceneProperty.sceneId']=_this.sceneId; 
            		var res = common_ajax.ajaxFunc('post', _this.ctx + "/scene/property/save", formData, "json", null);
                    layer.closeAll('loading');
                    if (res.code == 200) {
                        layer.close(dIndex);
                        layer.msg(res.message, {icon: 1});
                        _this.insTb.reload({where:{
                	    	thingId:_this.model.id
                	    }}, 'data');
                        let sensor=_this.globe.getById(_this.thingId);
                        if(sensor){
                        	sensor.updateProperty(res.data);
                        }
                        
                    } else {
                        layer.msg(res.message, {icon: 2});
                    }
                    return false;
                });
            }
        });
    }
}

ScenePointLibrary.prototype.updateImage = function() {
	var _this = this;
	var res = common_ajax.ajaxFunc('get', _this.ctx + "/scene/point/library", {}, "html", null);
	layer.closeAll('loading');
	if (!res) {
		layer.alert('系统异常！');
		return;
	}
	layer.open({
		id: 'scenePointLibrary',
		title: '图标库',
		type: 1,
		area: '220px',
		content: res,
		shade: 0,
		offset: ['0px', '305px'],
		skin: 'layui-layer layui-layer-adminRight layui-layer-city',
		success: function(layero, dIndex) {
			$(layero).children('.layui-layer-content').css('overflow', 'hidden');
			$(layero).children('.layui-layer-content').css('height', 'calc(100% - 30px)');
			_this.icondIndex = dIndex;
			_this.loadIcon();
		},
		end: function() {
			
		}
	});
}

ScenePointLibrary.prototype.loadIcon = function(classifyId) {
	var _this = this;
	var res = common_ajax.ajaxFunc('get', _this.ctx + "/scene/point/listDataForIcon", { classifyId: classifyId || $("#point-icon-classify-select").val() }, "json", null);
	if (0 == res.code) {
		res.ctx = _this.ctx;
		laytpl(selectModelsScript.innerHTML).render(res, function(html) {
			$('#select-point-icon-list').html(html);
			$(".IconImageList>.content>.item>.icon").on('click', function() {
				var res = common_ajax.ajaxFunc('get', _this.ctx + "/resources/icon/getById", {
					id:$(this).attr('id'),
				}, "json", null);
			    if (200==res.code && res.data) {
					console.log(res.data);
					$("#scene-point-image").attr('src',_this.ctx+res.data.url);
					$('#scenePointImage-input').val(res.data.url);
					$('#scenePointWidth').val(res.data.width);
					$('#scenePointHeight').val(res.data.height);
					if(_this.model){
						_this.model.updateImage({
							image:_this.ctx+res.data.url,
							width:res.data.width,
							height:res.data.height
						});
					}
				}
			})
		});
	}
}

ScenePointLibrary.prototype.delete = function(obj){
	let _this=this;
	if(!obj){
		layer.alert('删除失败，刷新重试！');
		return;
	}
	layer.load(2);
	var res = common_ajax.ajaxFunc('get', _this.ctx + "/scene/point/delete", {id:obj.id},"json", null);
	layer.closeAll('loading');
	if (res && 200==res.code) {
        layer.msg(res.message, {icon: 1});
		_this.close();
		_this.closeEditTool();		
		_this.globe.remove(obj.id);
        return true;
    } else {
        layer.msg(res.message, {icon: 2});
        return false;
    }
}

ScenePointLibrary.prototype.createEditTool=function(model){
	let _this=this;
	_this.EditPPointTool=_this.globe.createEditPPoint(model);
	_this.EditPPointTool.on('change',function(e){
		if(e.position){
			$("#pointX").val(e.position.x)
			$("#pointY").val(e.position.y)
			$("#pointZ").val(e.position.z)
		}
	});
}

ScenePointLibrary.prototype.closeEditTool=function(){
	let _this=this;
	if(_this.EditPPointTool){
		_this.EditPPointTool.destroy();
		_this.EditPPointTool=null;
	}
}

ScenePointLibrary.prototype.close = function(){
	var _this = this;
	if(_this.editPPointIndex){
		layer.close(_this.editPPointIndex);	
	}
}

